package routers

import (
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
	"hobby-mate/app/admin/apis/account"
	wechatapis "hobby-mate/app/wechat/apis"
	_ "hobby-mate/docs"
)

// BaseRouter 路由
// 路由规则：/api/系统/token或open或无前缀/具体接口
// for example：/api/sys/_login 等同于/api/sys/open/_login  无需cookie验证
// for example：/api/sys/open/_login 等同于/api/sys/_login  无需cookie验证
// for example：/api/sys/token/_login  需要cookie验证 否则返回401 无权限
type BaseRouter struct {
	Engine *gin.Engine
}

// WithAdminRouter 管理系统api
func (baseRouter *BaseRouter) WithAdminRouter() *BaseRouter {
	//system
	system := baseRouter.Engine.Group("/api/sys/")
	//基于token的接口=======================
	systemToken := system.Group("/token/")
	//Account模块
	systemTokenAccount := systemToken.Group("/account/")
	{
		systemTokenAccount.POST("/_add-account", account.Controller{}.CreateAccountApi)
		systemTokenAccount.GET("/_get-all-account/page", account.Controller{}.GetAllAccountByPageApi)
	}
	//基于open的接口=======================
	systemOpen := system.Group("/open/")
	// Account模块
	systemOpenAccount := systemOpen.Group("/account/")
	{
		systemOpenAccount.POST("/_login", account.Controller{}.LoginApi)
	}
	return baseRouter
}

// WithWechatRouter 微信小程序系统api
func (baseRouter *BaseRouter) WithWechatRouter() *BaseRouter {
	wechat := baseRouter.Engine.Group("api/wechat/")
	{
		wechat.POST("_some-endpoint", wechatapis.AccountController{}.GetUserPage)
	}
	return baseRouter
}

// WithCommonSwaggerRouter 通用swagger文档
func (baseRouter *BaseRouter) WithCommonSwaggerRouter() *BaseRouter {
	baseRouter.Engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	return baseRouter
}
